﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Analysis_Sorting_Algorithms
{
    class BubbleSort
    {
        public int[] sortIt(int[] array, ref int compare)
        {
            int size = array.Length;
            bool swapped = true;

            for (int i = 0; i < size && swapped; i++) //for each element while swapping has happened
            {
                swapped = false;    //no swapping has occured yet
                
                for (int j = 0; j < size - 1; j++) //for each element 
                {
                    if (array[j] > array[j + 1])// if element next to the current element is smaller swap
                    {
                        int temp = array[j + 1];
                        array[j + 1] = array[j];
                        array[j] = temp;
                        swapped = true;
                    }
                    compare++;
                }
            }
            return array;
        }
    }
}
